<?php

require_once ROOT_PATH . '/lib/models/surveys/Surveys.php';

class EXTRACTOR_Surveys {

	public function parseAddData($postArr) {
		
		// Extract dates		
		$postArr['txtFromDate'] = LocaleUtil::getInstance()->convertToStandardDateFormat($postArr['txtFromDate']);
		$postArr['txtToDate'] = LocaleUtil::getInstance()->convertToStandardDateFormat($postArr['txtToDate']);
		
		if(isset($postArr['cbActive']))
			$postArr['cbActive']=1;
		else
			$postArr['cbActive']=0;
		if(isset($postArr['cbShowResults']))
			$postArr['cbShowResults']=1;
		else
			$postArr['cbShowResults']=0;
			
		if(isset($postArr['cbResend'])){
			$postArr['cbResend']=1;
		}else{
			$postArr['cbResend']=0;
		}
		///die($postArr['cbActive']);
		$survey= new Surveys();
		$survey->setSurveyName($postArr['txtName']);
		$survey->setSurveyType($postArr['surveytype']);		
		$survey->setSurveyDescription($postArr['txtDescription']);
		$survey->setSurveyFromDate($postArr['txtFromDate']);
		$survey->setSurveyToDate($postArr['txtToDate']);
		$survey->setSurveyThanks($postArr['txtThanks']);
		$survey->setSurveyActive($postArr['cbActive']);
		$survey->setSurveyOwner($_SESSION['empID']);
		$survey->setSurveyResultsView($postArr['cbShowResults']);
                 	$survey->setSurveyEmailContent($postArr['txtEmailContent']);

			$survey->setSurveyResendEmail($postArr['cbResend']);

		return $survey;
	}
	
	public function parseEditData($postArr) {
		
		// Extract dates		
		$postArr['txtFromDate'] = LocaleUtil::getInstance()->convertToStandardDateFormat($postArr['txtFromDate']);
		$postArr['txtToDate'] = LocaleUtil::getInstance()->convertToStandardDateFormat($postArr['txtToDate']);
		
		if(isset($postArr['cbActive']))
			$postArr['cbActive']=1;
		else
			$postArr['cbActive']=0;	
		if(isset($postArr['cbShowResults']))
			$postArr['cbShowResults']=1;
		else
			$postArr['cbShowResults']=0;
			
		if(isset($postArr['cbResend'])){
			$postArr['cbResend']=1;
		}else{
			$postArr['cbResend']=0;
		}
		
		
		
		$survey = Surveys::getSurvey($postArr['txtId']);
		
		$survey->setSurveyName($postArr['txtName']);
		$survey->setSurveyType($postArr['surveytype']);			
		$survey->setSurveyDescription($postArr['txtDescription']);
		$survey->setSurveyFromDate($postArr['txtFromDate']);
		$survey->setSurveyToDate($postArr['txtToDate']);
		$survey->setSurveyThanks($postArr['txtThanks']);
		$survey->setSurveyActive($postArr['cbActive']);
		$survey->setSurveyResultsView($postArr['cbShowResults']);
		//$survey->setSurveyOwner($_SESSION['empID']);
		if(isset($postArr['employeeid'])){
			$surveyUsers = $postArr['employeeid']?implode(",",$postArr['employeeid']):"";
			$survey->setSurveyUsers($surveyUsers);
		}else{
			$survey->setSurveyUsers("");
		}
		
		$survey->setSurveyEmailContent($postArr['txtEmailContent']);
		$survey->setSurveyResendEmail($postArr['cbResend']);
		//print_r($survey);	
		//die("ehre");
		
		return $survey;
	}
}
?>